package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDTO;
import com.zzyl.service.NursingProjectPlanService;

import com.zzyl.vo.NursingPlanVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursing/plan")
@Api(value = "护理计划")
public class NursingProjectPlanController {

    @Autowired
    private NursingProjectPlanService nursingProjectPlanService;

    //查询全部
    @GetMapping
    @ApiOperation(value = "查询全部护理计划")
    public ResponseResult<List<NursingPlanVO>> getAll() {
        List<NursingPlanVO> nursingPlanVO = nursingProjectPlanService.select();
        return ResponseResult.success(nursingPlanVO);
    }

    //分页查询
    @GetMapping("/search")
    @ApiOperation(value = "分页查询护理计划")
    public ResponseResult<PageResponse<NursingPlanVO>> search(
            @ApiParam(value = "护理计划名称")
            @RequestParam(value = "name", required = false) String name,
            @ApiParam(value = "状态：0-禁用，1-启用")
            @RequestParam(value = "status", required = false) Integer status,
            @ApiParam(value = "当前页码")
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页显示数量")
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize
    ) {
        PageResponse<NursingPlanVO> nursingProjectPlanPageInfo = nursingProjectPlanService.selectPage(name, status, pageNum, pageSize);
        return ResponseResult.success(nursingProjectPlanPageInfo);
    }
    //新增
    @PostMapping
    @ApiOperation(value = "新增护理计划")
    public ResponseResult add(@ApiParam(value = "护理计划信息", readOnly = true) @RequestBody NursingPlanDTO NursingPlandto) {
        nursingProjectPlanService.add(NursingPlandto);
        return ResponseResult.success();
    }

    //根据id查询
    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查询护理计划")
    public ResponseResult<NursingPlanVO> getById(@ApiParam(value = "护理计划id") @PathVariable("id") Long id) {
        NursingPlanVO nursingProjectPlan = nursingProjectPlanService.getById(id);
        return ResponseResult.success(nursingProjectPlan);
    }

    //修改
    @PutMapping("/{id}")
    @ApiOperation(value = "修改护理计划")
    public ResponseResult update(@ApiParam(value = "护理计划信息", readOnly = true) @RequestBody NursingPlanDTO NursingPlandto, @ApiParam(value = "护理计划id") @PathVariable("id") Long id) {
        nursingProjectPlanService.update(NursingPlandto);
        return ResponseResult.success();
    }

    //删除
    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除护理计划")
    public ResponseResult delete(@ApiParam(value = "护理计划id") @PathVariable("id") Long id) {
        nursingProjectPlanService.delete(id);
        return ResponseResult.success();
    }

    //修改状态
    @PutMapping("/{id}/status/{status}")
    @ApiOperation(value = "修改护理计划状态")
    public ResponseResult updateStatus(@ApiParam(value = "护理计划id") @PathVariable("id") Long id, @ApiParam(value = "状态：0-禁用，1-启用") @PathVariable("status") Integer status) {
        nursingProjectPlanService.updateStatus(id, status);
        return ResponseResult.success();
    }
}
